// eslint.config.js
const vuePlugin = require('eslint-plugin-vue');
const typescriptEslint = require('@typescript-eslint/eslint-plugin');
const vueParser = require('vue-eslint-parser');
const tsParser = require('@typescript-eslint/parser');
const prettier = require('eslint-plugin-prettier');
const prettierConfig = require('eslint-config-prettier');
const autoImportConfig = require('./.eslintrc-auto-import.json');
module.exports = [
  // 基础配置 - 适用于所有文件
  {
    ignores: [
      'node_modules/',
      'dist/',
      '*.log',
      '.*',
      'src/test/legacy.js',
      'build/',
      'config/',
      'dist/',
      '*.js',
    ]
  },

  // JavaScript 配置
  {
    files: ['**/*.js'],
    rules: {
      ...prettierConfig.rules,
    }
  },

  // Vue + TypeScript 配置
  {
    files: ['**/*.vue', '**/*.ts', '**/*.tsx'],
    languageOptions: {
      parser: vueParser,
      parserOptions: {
        parser: tsParser,
        ecmaVersion: 'latest',
        sourceType: 'module',
        ecmaFeatures: {
          jsx: true
        },
        project: './tsconfig.eslint.json',
        extraFileExtensions: ['.vue']
      }
    },
    plugins: {
      vue: vuePlugin,
      '@typescript-eslint': typescriptEslint,
      prettier,
    },
    rules: {
      // Vue 推荐规则
      ...vuePlugin.configs['recommended'].rules,

      // TypeScript 推荐规则
      ...typescriptEslint.configs.recommended.rules,

      // Prettier 规则
      ...prettierConfig.rules,

      // 自动导入规则
      ...autoImportConfig.rules,

      // 自定义规则
      'prettier/prettier': 'error',

      '@typescript-eslint/ban-ts-ignore': 'off',
      '@typescript-eslint/explicit-function-return-type': 'off',
      '@typescript-eslint/no-explicit-any': 'off',
      '@typescript-eslint/no-var-requires': 'off',
      '@typescript-eslint/no-empty-function': 'off',
      '@typescript-eslint/ban-ts-comment': 'off',
      '@typescript-eslint/ban-types': 'off',
      '@typescript-eslint/no-non-null-assertion': 'off',
      '@typescript-eslint/explicit-module-boundary-types': 'off',
      '@typescript-eslint/no-unused-vars': 'error',

      'vue/custom-event-name-casing': 'off',
      'vue/attributes-order': 'off',
      'vue/one-component-per-file': 'off',
      'vue/html-closing-bracket-newline': 'off',
      'vue/max-attributes-per-line': 'off',
      'vue/multiline-html-element-content-newline': 'off',
      'vue/singleline-html-element-content-newline': 'off',
      'vue/attribute-hyphenation': 'off',
      'vue/require-default-prop': 'off',
      'vue/require-explicit-emits': 'off',
      'vue/multi-word-component-names': 'off',
      'vue/no-reserved-component-names': 'off',

      'no-unused-vars': 'off', // 使用 TypeScript 的版本
      'no-use-before-define': 'off',
      'space-before-function-paren': 'off',

      'vue/html-self-closing': [
        'error',
        {
          html: {
            void: 'always',
            normal: 'never',
            component: 'always',
          },
          svg: 'always',
          math: 'always',
        },
      ],
    },
  },
];
